package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.common.core.domain.entity.PanOverflowReport;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.PanOverflowReportMapper;
import com.ruoyi.system.service.IPanOverflowReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 报损单/报溢单Service业务层处理
 *
 * @author wlmes
 * @date 2023-11-24
 */
@Service
public class PanOverflowReportServiceImpl implements IPanOverflowReportService
{
    @Autowired
    private PanOverflowReportMapper panOverflowReportMapper;

    /**
     * 查询报损单/报溢单
     *
     * @param id 报损单/报溢单ID
     * @return 报损单/报溢单
     */
    @Override
    public PanOverflowReport selectPanOverflowReportById(Long id)
    {
        return panOverflowReportMapper.selectPanOverflowReportById(id);
    }

    /**
     * 查询报损单/报溢单列表
     *
     * @param panOverflowReport 报损单/报溢单
     * @return 报损单/报溢单
     */
    @Override
    public List<PanOverflowReport> selectPanOverflowReportList(PanOverflowReport panOverflowReport)
    {
        return panOverflowReportMapper.selectPanOverflowReportList(panOverflowReport);
    }

    /**
     * 新增报损单/报溢单
     *
     * @param panOverflowReport 报损单/报溢单
     * @return 结果
     */
    @Override
    public int insertPanOverflowReport(PanOverflowReport panOverflowReport)
    {
        if(StringUtils.isNull(panOverflowReport)) {
            throw new BaseException("新增报损单/报溢单失败！");
        }
        panOverflowReport.setCreateTime(DateUtils.getNowDate());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        panOverflowReport.setCreateBy(String.valueOf(user.getNickName()));
        return panOverflowReportMapper.insertPanOverflowReport(panOverflowReport);
    }

    /**
     * 修改报损单/报溢单
     *
     * @param panOverflowReport 报损单/报溢单
     * @return 结果
     */
    @Override
    public int updatePanOverflowReport(PanOverflowReport panOverflowReport)
    {
        panOverflowReport.setUpdateTime(DateUtils.getNowDate());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        panOverflowReport.setUpdateBy(String.valueOf(user.getNickName()));
        return panOverflowReportMapper.updatePanOverflowReport(panOverflowReport);
    }

    /**
     * 批量删除报损单/报溢单
     *
     * @param ids 需要删除的报损单/报溢单ID
     * @return 结果
     */
    @Override
    public int deletePanOverflowReportByIds(Long[] ids)
    {
        if(StringUtils.isNull(ids)){
            throw new BaseException("需要删除的报损单/报溢单ID为空！");
        }
        return panOverflowReportMapper.deletePanOverflowReportByIds(ids);
    }

    /**
     * 删除报损单/报溢单信息
     *
     * @param id 报损单/报溢单ID
     * @return 结果
     */
    @Override
    public int deletePanOverflowReportById(Long id)
    {
        if(StringUtils.isNull(id)){
            throw new BaseException("需要删除的报损单/报溢单ID为空！");
        }
        return panOverflowReportMapper.deletePanOverflowReportById(id);
    }
}
